package handler

import (
	"github.com/gin-gonic/gin"
	"message-queue_0826/api/params"
	"message-queue_0826/internal/mobel"
	"net/http"
)

func AddContact(c *gin.Context) {
	var req params.AddContactForm

	err := c.ShouldBindJSON(&req)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    100000,
			"message": "验证失败",
			"data":    "",
		})
		return
	}

	var contact mobel.Contact
	contact = mobel.Contact{
		Name:   req.Name,
		Mobile: req.Mobile,
	}

	err = contact.AddContact()
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    100000,
			"message": "联系人添加失败",
			"data":    "",
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "联系人添加成功",
		"data":    contact.Id,
	})
}
